package com.bilin.coin.widget;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.bilin.coin.R;
import com.bilin.coin.bean.UpDateMsgBean;
import com.bilin.coin.bean.VersionBean;

import org.greenrobot.eventbus.EventBus;


/**
 * Created by LG on 2018/5/8.
 */

public class UpDateDialog extends Dialog implements View.OnClickListener {

    private TextView tvConfirm;
    private TextView tvCancel;
    private TextView tvContent;
    private TextView tv_version;
    private boolean isOngoingUpdate;
    //private String strContent;
    private String mMianAndSet;
    private String newVersion;
    private String content;

    public UpDateDialog(Context context) {
        super(context);
    }


    public UpDateDialog(Context context, int themeResId, boolean isOngoingUpdate, String newVersion, String content, String mianAndSet) {
        super(context, themeResId);
        this.isOngoingUpdate = isOngoingUpdate;
        this.newVersion = newVersion;
        this.content = content;
        this.mMianAndSet = mianAndSet;
    }

    protected UpDateDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.update_dialog);
        tvConfirm = findViewById(R.id.tv_confirm);
        tvCancel = findViewById(R.id.tv_cancel);
        tvContent = findViewById(R.id.tv_content);
        tv_version = findViewById(R.id.tv_version);
        //View vLine = findViewById(R.id.v_line);

        tvConfirm.setOnClickListener(this);
        tvCancel.setOnClickListener(this);

        if (isOngoingUpdate) {
            tvCancel.setVisibility(View.GONE);
        }

        tv_version.setText(newVersion);

        if (!TextUtils.isEmpty(content)) {
            tvContent.setText(content.replace(";", "\n"));
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_confirm:
                if (mMianAndSet.equals("main")) {
                    EventBus.getDefault().post(new UpDateMsgBean(true, true));
                } else {
                    EventBus.getDefault().post(new UpDateMsgBean(true, false));
                }

                break;
            case R.id.tv_cancel:
                if (mMianAndSet.equals("main")) {
                    EventBus.getDefault().post(new UpDateMsgBean(false, true));
                } else {
                    EventBus.getDefault().post(new UpDateMsgBean(false, false));
                }


                break;
        }
    }


}
